package com.mianyang.zhangsan.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mianyang.zhangsan.common.base.BaseController;
import com.mianyang.zhangsan.common.base.R;
import com.mianyang.zhangsan.model.dto.SecBankChart;
import com.mianyang.zhangsan.model.entity.SecBank;
import com.mianyang.zhangsan.model.entity.SecProblem;
import com.mianyang.zhangsan.service.SecBankService;
import com.mianyang.zhangsan.service.SecProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jiangjr
 * @date 2022-11-30
 */
@RestController
@RequestMapping("/bank")
public class SecBankController extends BaseController {
    @Autowired
    private SecBankService bankService;

    /**
     * 查询题库
     */
    @GetMapping("/query")
    public R queryBank(SecBank bank,
                       @RequestParam(value = "current", defaultValue = "1") Integer current,
                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<SecBank> banks = bankService.selectBankByPage(bank, current, pageSize);
        return success("banks", banks);
    }

    /**
     * 删除题库
     */
    @DeleteMapping("/delete/{bankId}")
    public R deleteBank(@PathVariable("bankId") Long bankId) {
        bankService.removeById(bankId);
        return success();
    }

    /**
     * 修改题库
     */
    @PutMapping("/edit")
    public R editBank(@RequestBody SecBank bank) {
        bankService.updateById(bank);
        return success();
    }

    /**
     * 新增题库
     */
    @PostMapping("/add")
    public R addBank(@RequestBody SecBank bank) {
        bankService.save(bank);
        return success();
    }

    /**
     * 题库分析
     */
    @GetMapping("/analysis")
    public R bankAnalysis() {
        List<SecBankChart> charts = bankService.analysis();
        return success("charts", charts);
    }
}
